/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var ArrayBatchUtil = (function() {
    return {
        op: {
            "+": function(a, b) {
                return a + b;
            },
            "==": function(a, b) {
                return a == b;
            },
            "===": function(a, b) {
                return a === b;
            },
            "!": function(a) {
                return !a;
            }
            /* and so on */
        },
        forEach: function(array, action) {
            for (var i = 0; i < array.length; i++)
                action(array[i]);
        },
        reduce: function(combine, base, array) {
            forEach(array, function(element) {
                base = combine(base, element);
            });
            return base;
        },
        map: function(func, array) {
            var result = [];
            forEach(array, function(element) {
                result.push(func(element));
            });
            return result;
        },
        asArray: function(quasiArray, start) {
            var result = [];
            for (var i = (start || 0); i < quasiArray.length; i++)
                result.push(quasiArray[i]);
            return result;
        },
        partial: function(func) {
            var fixedArgs = asArray(arguments, 1);
            return function() {
                return func.apply(null, fixedArgs.concat(asArray(arguments)));
            };
        }
    };
}());

